home *** CD-ROM | disk | FTP | other *** search
/ Aminet 6 / Aminet 6 - June 1995.iso / Aminet / misc / amag / AM94122.lha / Monitor-Tuning / MPatch_MonitorInfo / MonitorInfo.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-24  |  7.9 KB  |  212 lines

  1. /*-------------------------------------------------------------------------
  2. --
  3. -- MonitorInfo.C
  4. --
  5. -- A small program to display a monitor's properties 
  6. --
  7. -- author: Gregor S. M. Kuhlmann
  8. --
  9. -- revision history:
  10. -- 1994-Apr-01    37.0  created
  11. -- 1994-Apr-02    37.1  added analogsignal period output in microseconds
  12. -- 1994-Apr-03    37.2  added ms_Flags interpretation
  13. -- 1994-Apr-04    37.3  added LIST option
  14. -- 1994-Apr-09    37.4  added RAW option
  15. -- 1994-Apr-21    37.5  some minor adjustments to interval calculation
  16. -- 1994-May-04    37.6  now adds ".monitor" extension if necessary
  17. -- 1994-Jun-01    37.7  fine adjustment in HB registers
  18. -- 1994-Aug-24    37.8  now displays MINCOL as well
  19. --
  20. -------------------------------------------------------------------------*/
  21.  
  22. #define __USE_SYSBASE
  23.  
  24. #include <stdio.h>
  25. #include <stdlib.h>
  26. #include <string.h>
  27. #include <math.h>
  28. #include <exec/types.h>
  29. #include <exec/execbase.h>
  30. #include <graphics/monitor.h>
  31. #include <graphics/gfxbase.h>
  32. #include <proto/dos.h>
  33. #include <proto/exec.h>
  34. #include <proto/graphics.h>
  35.  
  36. #define BOLD_ON         "\x1b[1m"
  37. #define BOLD_OFF        "\x1b[22m"
  38. #define UNDERLINE_ON    "\x1b[4m"
  39. #define UNDERLINE_OFF   "\x1b[24m"
  40.  
  41. extern long __oslibversion = 37;
  42.  
  43. extern char __stdiowin[] = "CON:0/0/300/160/";
  44. extern char __stdiov37[] = "/AUTO/CLOSE/WAIT";
  45.  
  46. static char version[] = "$VER: MonitorInfo 37.8 (24.8.94)";
  47.  
  48. static char *beamcon0defs[16] =
  49. {
  50.    "HSYNCTRUE   - horizontal sync true",
  51.    "VSYNCTRUE   - vertical sync true",
  52.    "CSYNCTRUE   - composite sync true",
  53.    "CSBLANK     - composite blank out to /CSY pin (ECS), unused (AA)",
  54.    "VARCSYNC    - variable composite sync enabled",
  55.    "DISPLAYPAL  - uses PAL color encoding",
  56.    "DISPLAYDUAL - uses both UHRES and standard pointers",
  57.    "VARBEAM     - variable beam counter enabled",
  58.    "VARHSYNC    - variable horizontal sync enabled",
  59.    "VARVSYNC    - variable vertical sync enabled",
  60.    "CSCBLANKEN  - redirect composite sync",
  61.    "LOLDIS      - long display lines disabled",
  62.    "VARVBLANK   - variable vertical blank enabled",
  63.    "LPENDIS     - disable lightpen position latch",
  64.    "HARDDIS     - disable hardwired display window limits",
  65.    NULL
  66. };
  67.  
  68. float color_clock = 280e-9;   /* color clock default value */
  69.  
  70. float signalInterval(UWORD registerValue)
  71. {
  72.    float result;
  73.    
  74.    result = color_clock * (registerValue & 0xFF);
  75.    if (registerValue & (1<<10)) result+=color_clock / 2.0;
  76.    if (registerValue & (1<<9)) result+=color_clock / 4.0;
  77.    if (registerValue & (1<<8)) result+=color_clock / 8.0;
  78.    return(result);
  79. }
  80.  
  81. void main(void)
  82. {
  83.    struct MonitorSpec *mspec;
  84.    struct SpecialMonitor *sm;
  85.    float base_frequency, v_freq;
  86.    float ratioh, ratiov;
  87.    UWORD i;
  88.    char **monitorName;
  89.    int numMonitors = 0;
  90.    BOOL rawmode = FALSE;
  91.    static char template[] = "MONITORS/M,LIST/S,RAW/S";
  92.    LONG values[3] = {0,0,0};
  93.    char buffer[32];
  94.    char *bufptr;
  95.    struct RDArgs *ra;
  96.    long rc = RETURN_OK;
  97.    
  98.    printf("\n" BOLD_ON "%s" BOLD_OFF "   by Gregor S. M. Kuhlmann\n\n",&version[6]);
  99.    
  100.    if (ra=ReadArgs(template,values,0))
  101.    {   
  102.       if ((values[1]) || (values[0]==NULL))
  103.       {   
  104.          ObtainSemaphoreShared(GfxBase->MonitorListSemaphore);
  105.          printf(BOLD_ON UNDERLINE_ON "Currently installed monitors:" BOLD_OFF UNDERLINE_OFF "\n");
  106.          mspec = (struct MonitorSpec *)GfxBase->MonitorList.lh_Head;
  107.          while (mspec->ms_Node.xln_Succ)
  108.          {
  109.             numMonitors++;
  110.             printf("%s\n",mspec->ms_Node.xln_Name);
  111.             mspec=(struct MonitorSpec *)mspec->ms_Node.xln_Succ;
  112.          }
  113.          if (numMonitors==0)
  114.          {
  115.             printf("< NONE >\n");
  116.          }
  117.          printf("\n");
  118.          ReleaseSemaphore(GfxBase->MonitorListSemaphore);
  119.       }
  120.       else 
  121.       {  
  122.          if (values[2])
  123.          {
  124.             rawmode=TRUE;
  125.          }
  126.          monitorName=(char**)values[0];
  127. /*--- determine color clock period display mode ---*/
  128.          color_clock = 1.0 / (5 * SysBase->ex_EClockFrequency);
  129.          printf("DMA Clock Cycle = %.2f ns\n\n",color_clock * 1e9);
  130.          while(*monitorName)
  131.          {
  132.             strcpy(buffer,*monitorName);
  133.             bufptr=buffer;
  134.             while((*bufptr) && (*bufptr!='.')) bufptr++;
  135.             if (*bufptr==0) strcat(buffer,".monitor");
  136.             if (mspec=OpenMonitor(buffer,0L))
  137.             {
  138.                printf(BOLD_ON UNDERLINE_ON "Information for '%s':" BOLD_OFF UNDERLINE_OFF "\n\n",buffer);
  139. /*--- print scan rates ---*/
  140.                printf(BOLD_ON "Display scan rates:" BOLD_OFF "\n");
  141.                if (mspec->BeamCon0 & (LOLDIS|DISPLAYPAL))
  142.                   base_frequency = 1.0 / ((mspec->total_colorclocks + 1.0) * color_clock);
  143.                else
  144.                   base_frequency = 1.0 / ((mspec->total_colorclocks + 1.5) * color_clock);
  145.                ratioh=mspec->ratioh/16.0;
  146.                ratiov=mspec->ratiov/16.0;
  147.                v_freq = base_frequency / mspec->total_rows;
  148.                printf("horizontal sweep rate = %.2f kHz (scanline period = %.2f µs)\n",
  149.                      base_frequency / 1000.0, (1.0 / base_frequency) * 1e6);
  150.                printf("vertical sweep rate = %.2f Hz\n",v_freq);
  151.                printf("lores pixel aspect ratio (w/h) = %.3f\n\n",ratiov/ratioh);
  152. /*--- print analogsignal properties ---*/
  153.                if (sm=mspec->ms_Special)
  154.                {
  155.                   if (rawmode)
  156.                   {
  157.                      printf(BOLD_ON "hardware timing values:" BOLD_OFF "\n");
  158.                      printf("TOTAL_ROWS=%d, MIN_ROW=%d, TOTAL_COLORCLOCKS=%d, MIN_COL=%d\n\n",
  159.                         mspec->total_rows,mspec->min_row,mspec->total_colorclocks,mspec->DeniseMinDisplayColumn);
  160.                      printf(BOLD_ON "hardware sync/blank values:" BOLD_OFF "\n");
  161.                      printf("HBSTRT=%d, HSSTRT=%d, HSSTOP=%d, HBSTOP=%d\n",
  162.                         sm->hblank.asi_Start,sm->hsync.asi_Start,sm->hsync.asi_Stop,sm->hblank.asi_Stop);
  163.                      printf("VBSTRT=%d, VSSTRT=%d, VSSTOP=%d, VBSTOP=%d\n\n",
  164.                         sm->vblank.asi_Start,sm->vsync.asi_Start,sm->vsync.asi_Stop,sm->vblank.asi_Stop);
  165.                   }     
  166.                   else
  167.                   {
  168.                      printf(BOLD_ON "special signal timing info:" BOLD_OFF "\n");
  169.                      printf("horizontal blanking period: %.2f µs\n",
  170.                         (signalInterval(sm->hblank.asi_Stop)-signalInterval(sm->hblank.asi_Start)) * 1e6);
  171.                      printf("horizontal sync period: %.2f µs (delay = %.2f µs)\n",
  172.                         (signalInterval(sm->hsync.asi_Stop)-signalInterval(sm->hsync.asi_Start)) * 1e6,
  173.                         (signalInterval(sm->hsync.asi_Start)-signalInterval(sm->hblank.asi_Start)) * 1e6);
  174.                      printf("vertical blanking period: %.2f µs\n", 
  175.                         (sm->vblank.asi_Stop-sm->vblank.asi_Start) * color_clock * 1e6);
  176.                      printf("vertical sync period: %.2f µs (delay = %.2f µs)\n\n",
  177.                         (sm->vsync.asi_Stop-sm->vsync.asi_Start) * color_clock * 1e6,
  178.                         (sm->vsync.asi_Start-sm->vblank.asi_Start) * color_clock * 1e6);
  179.                   }
  180.                }
  181. /*--- print beamcon properties ---*/               
  182.                printf(BOLD_ON "signal properties" BOLD_OFF " (BEAMCON0=0x%0.4x):\n",mspec->BeamCon0);
  183.                for (i=0;i<16;i++)
  184.                {
  185.                   if (mspec->BeamCon0 & (1<<i))
  186.                   {
  187.                      if (beamcon0defs[i])
  188.                         printf("%s\n",beamcon0defs[i]);
  189.                      else
  190.                         printf("(#%d)\n",i);
  191.                   }
  192.                }
  193.                printf("\n");
  194.                CloseMonitor(mspec);
  195.             }
  196.             else
  197.             {
  198.                printf("ERROR: Couldn't open monitor '%s'\n",buffer);
  199.                break;
  200.             }
  201.             monitorName++;
  202.          }
  203.       }
  204.    }
  205.    else
  206.    {
  207.       printf("ERROR: Arguments not suitable for template:\n%s\n",template);
  208.       rc=RETURN_ERROR;
  209.    }
  210.    exit(rc);
  211. }
  212.